import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

<<<<<<< HEAD
=======
import Home from '../views/home'
import Layout from "../../src/views/layout"
import Login from "../views/login"
import Register from "../views/register"
import NoFound from "../views/nofound"
import store from '@/store'
>>>>>>> dev
Vue.use(VueRouter)

export const routes = [
  {
<<<<<<< HEAD
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
=======
    path: "/",
    component: Layout,  //所有一级全部都是Layout  登录除外   
    meta: { title: "首页", icon: "Ticket" },
    redirect: '/login',
    // name: "首页",
    children: [
      {
        path: "/Home",
        component: () => import("../views/home"),
        meta: {
          title: "首页",
          icon: "HomeFilled"
        }
      }
    ]
  },
  {
    path: "/product",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "商品服务", icon: "Edit" },
    redirect: '/product/serve',
    children: [
      // {
      //   path: "/product/serve",
      //   component: () => import("../views/product-serve/serve.vue"),
      //   meta: {
      //     title: "服务管理",
      //     icon: "HomeFilled"
      //   }
      // },
      {
        path: "/product/pro",
        component: () => import("../views/product-serve/pro.vue"),
        meta: {
          title: "商品管理",
          icon: "HomeFilled"
        }
      }
    ]
  },
  {
    path: "/order",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "订单管理", icon: "Edit" },
    redirect: '/order/line',
    children: [
      {
        path: "/order/line",
        component: () => import("../views/order/index.vue"),
        meta: {
          title: "线上订单",
          icon: "HomeFilled"
        }
      },
      // {
      //   path: "/product/yyorder",
      //   component: () => import("../views/order/yyorder.vue"),
      //   meta: {
      //     title: "预约订单",    //不一定有？
      //     icon: "HomeFilled"
      //   }
      // }
    ]
  },
  {
    path: "/foster",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "寄养管理", icon: "Ticket" },
    redirect: '/foster',
    // foster 完成
    children: [
      {
        path: "/foster/foster",
        component: () => import("../views/inventory"),
        meta: {
          title: "寄养管理",
          icon: "HomeFilled"
        }
      },
    ]
  },
  {
    path: "/vip",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "会员中心", icon: "Ticket" },
    redirect: '/vip/vip',
    children: [
      {
        path: "/vip/vip",
        component: () => import("../views/vip/index.vue"),
        meta: {
          title: "会员管理",
          icon: "HomeFilled"
        }
      },
      {
        path: "/vip/rules",
        component: () => import("../views/vip/rules.vue"),
        meta: {
          title: "会员规则",
          icon: "HomeFilled"
        }
      },
      {
        path: "/vip/Rroder",
        component: () => import("../views/vip/Rroder.vue"),
        meta: {
          title: "充值订单",
          icon: "HomeFilled"
        }
      }
    ]
  },
  // {
  //   path: "/inventory",
  //   component: Layout,  //所有一级全部都是Layout  登录除外
  //   meta: { title: "库存管理", icon: "Ticket" },
  //   redirect: '/foster/foster',
  //   children: [
  //     {
  //       path: "/foster/foster",
  //       component: () => import("../views/foster/index.vue"),
  //       meta: {
  //         title: "商品库存",
  //         icon: "HomeFilled"
  //       }
  //     },
  //     {
  //       path: "/foster/record",
  //       component: () => import("../views/foster/record.vue"),
  //       meta: {
  //         title: "入库记录",
  //         icon: "HomeFilled"
  //       }
  //     }
  //   ]
  // },
  {
    path: "/center",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "财务中心", icon: "Ticket" },
    redirect: '/center',
    name:"财务中心",
    children: [
      {
        path: "/center/center",
        component: () => import("../views/money/index.vue"),
        meta: {
          title: "财务中心",
          icon: "HomeFilled"
        }
      },]
    
  },
  {
    path: "/clert",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "店员管理", icon: "Ticket" },
    redirect: '/clert',
    name:"店员管理",
    children: [
      {
        path: "/clert/clert",
        component: () => import("../views/clerk/index.vue"),
        meta: {
          title: "店员管理",
          icon: "HomeFilled"
        }
      },]

  },
  {
    path: "/login",
    name: "login",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "请登录"
    },
    component: Login
  },
  {
    path: "/register",
    name: "register",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "请注册"
    },
    component: Register
  },
  {
    path:"*",
    name: "NoFound",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "NoFound"
    },
    component:NoFound
>>>>>>> dev
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  // routes:[...asyncRoutes,...staticRoutes]
  routes
})

<<<<<<< HEAD
=======
export const asyncRoutes = [
  {
    path: "/",
    component: Layout,  //所有一级全部都是Layout  登录除外   
    meta: { title: "首页", icon: "Ticket" },
    redirect: '/Home',
    // name: "首页",
    children: [
      {
        path: "/Home",
        component: () => import("../views/home"),
        meta: {
          title: "首页",
          icon: "HomeFilled"
        }
      }
    ]
  },
  {
    path: "/product",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "商品服务", icon: "Edit" },
    redirect: '/product/serve',
    children: [
      {
        path: "/product/pro",
        component: () => import("../views/product-serve/pro.vue"),
        meta: {
          title: "商品管理",
          icon: "HomeFilled"
        }
      }
    ]
  },
  {
    path: "/order",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "订单管理", icon: "Edit" },
    redirect: '/order/line',
    children: [
      {
        path: "/order/line",
        component: () => import("../views/order/index.vue"),
        meta: {
          title: "线上订单",
          icon: "HomeFilled"
        }
      },
    ]
  },
  {
    path: "/foster",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "寄养管理", icon: "Ticket" },
    redirect: '/foster',
    // foster 完成
    children: [
      {
        path: "/foster/foster",
        component: () => import("../views/inventory"),
        meta: {
          title: "寄养管理",
          icon: "HomeFilled"
        }
      },
    ]
  },
  {
    path: "/vip",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "会员中心", icon: "Ticket" },
    redirect: '/vip/vip',
    children: [
      {
        path: "/vip/vip",
        component: () => import("../views/vip/index.vue"),
        meta: {
          title: "会员管理",
          icon: "HomeFilled"
        }
      },
      {
        path: "/vip/rules",
        component: () => import("../views/vip/rules.vue"),
        meta: {
          title: "会员规则",
          icon: "HomeFilled"
        }
      },
      {
        path: "/vip/Rroder",
        component: () => import("../views/vip/Rroder.vue"),
        meta: {
          title: "充值订单",
          icon: "HomeFilled"
        }
      }
    ]
  },
  {
    path: "/center",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "财务中心", icon: "Ticket" },
    redirect: '/center',
    name:"财务中心",
    children: [
      {
        path: "/center/center",
        component: () => import("../views/money/index.vue"),
        meta: {
          title: "财务中心",
          icon: "HomeFilled"
        }
      },]
    
  },
  {
    path: "/clert",
    component: Layout,  //所有一级全部都是Layout  登录除外
    meta: { title: "店员管理", icon: "Ticket" },
    redirect: '/clert',
    name:"店员管理",
    children: [
      {
        path: "/clert/clert",
        component: () => import("../views/clerk/index.vue"),
        meta: {
          title: "店员管理",
          icon: "HomeFilled"
        }
      },]
  },
]
const staticRoutes = [
  {
    path: "/login",
    name: "login",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "请登录"
    },
    component: Login
  },
  {
    path: "/register",
    name: "register",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "请注册"
    },
    component: Register
  },
  {
    path:"*",
    name: "NoFound",
    meta: {
      hidden: true, //左侧菜单隐藏
      title: "NoFound"
    },
    component:NoFound
  },
]



// 全局前置钩子
router.beforeEach((to,from,next)=>{
  //可以加入过场动画 判断是否登录
  //设置title
  document.title = to.meta?.title
  //是否登录
   const token = JSON.parse(sessionStorage.getItem("Vuex-Persistence"))?.user.token
    if(token || to.name == 'login' || to.name == 'register'){
      next()
    }else{
      //重定向的路径携带到登录
      next('/login?redirect=' + to.path)
    }

  // console.log(to.path,"去的路径")
  // console.log(staticRoutes,"路由");
  // console.log(staticRoutes.includes(to.path),"是否包含");
  // if(staticRoutes.includes(to.path)){
  //   //非权限页面 直接放行
  //   console.log(1);
  //   next()
  //   console.log(2);
  // }
  // else{
  // const token = JSON.parse(sessionStorage.getItem("Vuex-Persistence"))?.user.token
  // console.log(token,"token");
  //   if(token){
  //     next()
  //   }else{
  //     next("/login")
  //   }
  // }
  
})

router.afterEach(()=>{



})



>>>>>>> dev
export default router
